package com.aiwei.tdjk.utils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by zhou on 2017/5/17.
 */
public final class SameElementUtil {
    /**
     * 筛选多个list中的相同元素
     * @param lists
     * @param <E>
     * @return
     */
    public static <E> List<E> findSameElem(List<List<E>> lists) {
        if (lists.size() == 0) return Collections.emptyList();
        List<E> tmpList = new ArrayList<>(lists.get(0));
        for (int i = 1; i < lists.size(); i++) {
            List<E> aList = lists.get(i);
            tmpList.retainAll(aList);
        }
        return tmpList;
    }
}
